home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / boot / blitscroll.lha / blitscroll.e next >
Encoding:
Text File  |  1997-08-24  |  2.5 KB  |  101 lines

  1. /* setf.e -- a SnoopDos-like program to monitor calls to OpenLibrary() */
  2.  
  3. OPT OSVERSION=37
  4.  
  5. MODULE 'dos/dos', 'exec/ports', 'exec/tasks', 'exec/nodes', 'exec/memory'
  6. MODULE 'graphics/rastport'
  7.  
  8. /* "port" will be used from the patched routine, too, so it's global */
  9. DEF port:PTR TO mp
  10.  
  11. CONST SCROLLRASTER = $fe74
  12.  
  13. /* You can change the library function to be patched by changing OFFSET
  14.    and the "execbase" in the *two* calls to SetFunction().  If you want to
  15.    patch a library other than dos, exec, graphics and intuition you need
  16.    to OpenLibrary() it first.
  17.    (Note: some [old?] libraries cannot be patched in this way.  Also, some
  18.    functions in some libraries can't be patched like this either!  Even the
  19.    RKRM's aren't too clear about this...)
  20. */
  21. PROC main()
  22.   DEF oldf
  23.  
  24.   IF port:=CreateMsgPort()
  25.     Forbid()     /* Don't let anyone mess things up... */
  26.     IF oldf:=SetFunction(gfxbase, SCROLLRASTER, {newf})
  27.       PutLong({patch}, oldf)
  28.       Permit()    /* Now we can let everyone else back in */
  29.       LEA store(PC), A0
  30.       MOVE.L A4, (A0)    /* Store the A4 register... */
  31.       Wait(SIGBREAKF_CTRL_C)
  32.       Forbid()   /* Paranoid... */
  33.       SetFunction(gfxbase, SCROLLRASTER, oldf)
  34.     ENDIF
  35.     Permit()
  36.     DeleteMsgPort(port)
  37.   ELSE
  38.     PutStr('Unable to create message port\n')
  39.   ENDIF
  40. ENDPROC
  41.  
  42. PROC myscrollraster()    ->rp_ptr:PTR TO rastport, deltax, deltay, x, y, x2, y2)
  43.   DEF rp_ptr:rastport, deltax, deltay, x, y, x2, y2
  44.   DEF rpx, rpy, rpx2, rpy2, width, height
  45.  
  46.  /* DEF tsk:tc, l:ln
  47.  
  48.   tsk := FindTask(NIL)
  49.  
  50.   IF tsk THEN l:=tsk.ln  */
  51.  
  52.   MOVE.L A1, rp_ptr
  53.   MOVE.L D0, deltax
  54.   MOVE.L D1, deltay
  55.   MOVE.L D2, x
  56.   MOVE.L D3, y
  57.   MOVE.L D4, x2
  58.   MOVE.L D5, y2
  59.  
  60.   IF (deltax >= 0)
  61.     rpx   := x + deltax
  62.     rpx2  := x
  63.     width := (-x + (x2 + 1)) - deltax
  64.   ELSE
  65.     rpx   := x
  66.     rpx2  := x - deltax
  67.     width := (-x + (x2 + 1)) + deltax
  68.   ENDIF
  69.  
  70.   IF (deltay >= 0)
  71.     rpy    := y + deltay
  72.     rpy2   := y
  73.     height := (-y + (y2 + 1)) - deltay
  74.   ELSE
  75.     rpy    := y
  76.     rpy2   := y - deltay
  77.     height := (-y + (y2 + 1)) + deltay
  78.   ENDIF
  79.  
  80.   ClipBlit(rp_ptr, rpx,  rpy,
  81.            rp_ptr, rpx2, rpy2,
  82.                    width, height,
  83.                    $0C0)
  84. ENDPROC
  85.  
  86.  
  87. /* Place to store A4 register */
  88. store:  LONG 0
  89. /* Place to store real call */
  90. patch:  LONG 0
  91.  
  92. /* The new routine which will replace the original library function */
  93. newf:
  94.   MOVEM.L D0-D7/A0-A6, -(A7)
  95.   LEA store(PC), A0
  96.   MOVE.L (A0), A4 /* Reinstate the A4 register so we can use E code */
  97.   myscrollraster()
  98.   MOVEM.L (A7)+, D0-D7/A0-A6
  99.   ->MOVE.L patch(PC), -(A7)
  100.   RTS
  101.